package chap13;//********************************************************************
//  Magazine.java       Author: Lewis/Loftus
//
//  Represents a single magazine.
//********************************************************************

import java.util.Objects;

public class Magazine implements Comparable{
   private String title;

   //-----------------------------------------------------------------
   //  Sets up the new magazine with its title.
   //-----------------------------------------------------------------
   public Magazine(String newTitle) {
      title = newTitle;
   }

   //-----------------------------------------------------------------
   //  Returns this magazine as a string.
   //-----------------------------------------------------------------
   public String toString() {
      return title;
   }

    @Override
    public int compareTo(Object magazine) {
        int i = 0;
        int a;
        Magazine mag = (Magazine)magazine;
        while (title.charAt(i) == mag.toString().charAt(i)) {
            i++;
        }
        if ((int) (title.charAt(i)) < (int) (mag.toString().charAt(i)))
            a = -1;
        else
            a = 1;
        return a;
    }
}


